<?php session_start(); ?>
<?php
include('../ketnoi.php');
if (!$_SESSION['user']) header("location: index.php"); // nếu biến session['banguyen'] chưa có thì trở về trang đăng nhập, copy dòng này vào trang nào muốn bảo vệ bằng mật khẩu
?>
<style type="text/css">
<!--
.error, .success {padding:.8em; margin-bottom:.5em;border:2px solid #AAF;width:505px; text-align:center}
.error {background: #ECECFF;color: red;border-color:#AAF;}
.success {background: #ECECFF;color: #00F;border-color:#AAF;}
-->
</style>
<?php
$shop=$dulieu;
if($_GET['action']=='view' && $_GET['option']=='com_chanpass')
{
	if ( isset( $_POST['newpassword'] ) ){
		if($_POST['newpassword'] == ''){
			   $error='Lỗi : Mật khẩu mới không được để trống!!!';
			   $success='';
		    }else{
			   if(strlen($_POST['newpassword']) < 5){
			      $error='Lỗi : Mật khẩu mới phải có ít nhất 5 ký tự!!!';
				  $success='';
		       }else{
				  if($_POST['newpassword'] != $_POST['cfpassword']){
			          $error='Lỗi : Hai mật khẩu không giống nhau!!!';
					  $success='';
		          }else{
					  $pass = md5(md5($_POST["oldpassword"]));
					  $newpass = md5(md5($_POST["newpassword"]));
                      $sql = "SELECT count(NV_MA) FROM `".$shop."`.`nhanvien` WHERE NV_MA='".$_SESSION['user']."' AND NV_PASS='".$pass."'";
                      $kq = mysql_query($sql);
		              $tong=mysql_num_rows($kq);
                      if($tong==1){
						  $sql = "UPDATE `".$shop."`.`nhanvien` SET `NV_PASS` = '".$newpass."', `NV_MA` = '".$_SESSION['user']."' ";
                          $update = mysql_query($sql);
						  
                          $success='Thay đổi mật khẩu thành công!!!';
					      $error='';
                      }else{
			               $error='Lỗi : Mật khẩu cũ không chính xác!!!';
						   $success='';
                      }
			      }		   
			   }
			}
       }
	?>
<div class="m">
<div id="menu">
	<div style="float: right;">
	<div class="icon1">
<a  class="toolbar" href="index.php"><img src="images/toolbar/icon-32-cancel.png" alt="Cancel"><br><span>Cancel</span></a>
	</div>
	</div>
	
	<div style="float: right;">
	<div class="icon1">
<a class="toolbar" onclick="adminForm3.submit();"><img src="images/toolbar/icon-32-save.png"  alt="New"><br><span>Save</span></a>
	</div>
	</div>
</div>

<div style="background: url(images/dashboard/shop_users.png) no-repeat scroll 0% 0% transparent; text-indent: 30px; line-height: 50px;">
<h2 style="margin: 0px; font-size:22px; font-family: 'Times New Roman', Times, serif;">&nbsp;&nbsp;&nbsp;&nbsp;Nhân viên:<span style=" color:#C30"> [ Đổi mật khẩu]</span></h2></div><br /><br />
<?php if($error!=''){ ?><div class="error" ><img src='{$smarty.const.SITE_URL}images/cancel_f2.png' width='10px' height='10px'/>&nbsp;&nbsp;<?php echo $error ?></div><?php } ?>
<?php if($success!=''){ ?><div class="success" ><img src='{$smarty.const.SITE_URL}images/checkin.png' width='10px' height='10px'/>&nbsp;&nbsp;<?php echo $success ?></div><?php } ?>
<form name="adminForm3" action="" method="post" enctype="multipart/form-data">
  
  <div style="height: auto;" id="ext-gen37">
<div class="tab-page" id="info-page">
<table  class="adminform" style=" width:50%;">
	<tbody><tr> 
   		<td width="526" valign="top">
			<table width="94%" border="0">
      			<tbody>
                <tr> 
       				<td colspan="2" align="left"><span style="font-weight:bold; font-size:14px; color:#00F">Change password </span></td>
    			</tr>
    			<tr class="row0"> 
      				<td width="46%"><div style="text-align: right; font-weight: bold; font-size:12px">
					Tên đăng nhập:</div>      				</td>
      				<td width="54%"><input style="width:200px; margin-left:10px" disabled="disabled" name="username" size="32" maxlength="255" type="text" value="<?php echo $_SESSION['user'] ?>"/></td>
    			</tr>
                <tr class="row1"> 
				   <td width="46%"><div style="text-align: right; font-weight: bold;font-size:12px">Mật khẩu củ:</div>      				</td>
				   <td width="54%"><input style="width:200px; margin-left:10px" name="oldpassword" size="32" maxlength="255" type="password" value="" /></td>
				   </tr>
				 <tr class="row0"> 
				   <td width="46%"><div style="text-align: right; font-weight: bold;font-size:12px">Mật khẩu mới:</div>      				</td>
				   <td width="54%"><input style="width:200px; margin-left:10px" name="newpassword" size="32" maxlength="255" type="password" /></td>
				   </tr>
				<tr class="row1"> 
      				<td width="46%"><div style="text-align: right; font-weight: bold;font-size:12px">Xác nhận mật khẩu:</div>      				</td>
      				<td width="54%"><input style="width:200px; margin-left:10px" name="cfpassword" size="32" maxlength="255" type="password"> </td>
    			</tr>
    			  <tr class="row0"> 
    					    
		      		<td valign="top" width="46%">&nbsp;</td>
		      		<td width="54%">&nbsp;</td>		    
	    			</tr>
	  			  </tbody></table>
 		</td>
  	</tr>
</tbody></table>

</div>
</div>
</form>
</div>
<?php } ?>